<template>
  <div class="app-container">
    <el-form
      :model="queryParams"
      ref="queryForm"
      size="small"
      :inline="true"
      v-show="showSearch"
    >
      <el-form-item label="关键字" prop="deptName">
        <el-input
          v-model="queryParams.deptName"
          placeholder="请输入部门名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>

      <el-form-item>
        <el-button
          type="primary"
          icon="el-icon-search"
          size="mini"
          @click="handleQuery"
          >搜索</el-button
        >
      </el-form-item>
    </el-form>

    <el-table
      height="85%"
      :header-cell-style="{ background: '#F3F5FC' }"
      v-if="refreshTable"
      v-loading="loading"
      :data="deptList"
      row-key="stdId"
    >
      <el-table-column type="expand" width="30" class="innner">
        <template slot-scope="props">
          <el-table :data="props.row.details" :show-header="false" style="padding:0">
            <el-table-column prop="stdItemName"></el-table-column>
               <el-table-column prop="sort"></el-table-column>
           </el-table>
        </template>
      </el-table-column>
      <el-table-column prop="stdName" label="字典名称"></el-table-column>
      <el-table-column prop="stdCode" label="字典编码"></el-table-column>

      <el-table-column
        label="操作"
        align="center"
        class-name="small-padding fixed-width"
      >
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
                   @click="handleUpdate(scope.row)"
            >修改</el-button
          >
        </template>
      </el-table-column>
    </el-table>

    <!-- 添加或修改部门对话框 -->
    <attr-dia ref="attr_dia" :tableData="tableData"></attr-dia>
    <!-- 分页器 -->
    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
  </div>
</template>

<script>
import moni from "../../../components/security/moni.json";
import { listDept } from "@/api/system/dept";
import Treeselect from "@riophae/vue-treeselect";
import "@riophae/vue-treeselect/dist/vue-treeselect.css";
import AttrDia from "../../../components/Dialogs/AttrDia.vue";

export default {
  name: "Dept",
  dicts: ["sys_normal_disable"],
  components: { Treeselect, AttrDia },
  data() {
    return {
      // 总条数
      total: 0,
      // 遮罩层
      loading: true,
      // 显示搜索条件
      showSearch: true,
      // 表格树数据
      deptList: [],
      // 部门树选项
      deptOptions: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 是否展开，默认全部展开
      isExpandAll: true,
      // 重新渲染表格状态
      refreshTable: true,
      // 查询参数
      queryParams: {
        deptName: undefined,
        status: undefined,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        parentId: [
          { required: true, message: "上级部门不能为空", trigger: "blur" },
        ],
        deptName: [
          { required: true, message: "部门名称不能为空", trigger: "blur" },
        ],
        orderNum: [
          { required: true, message: "显示排序不能为空", trigger: "blur" },
        ],
        email: [
          {
            type: "email",
            message: "请输入正确的邮箱地址",
            trigger: ["blur", "change"],
          },
        ],
        phone: [
          {
            pattern: /^1[3|4|5|6|7|8|9][0-9]\d{8}$/,
            message: "请输入正确的手机号码",
            trigger: "blur",
          },
        ],
      },
      tableData: [
        {
          index: 1,
          name: "未超期",
          code: 0,
          operate: "---",
        },
        {
          index: 2,
          name: "超期",
          code: 1,
          operate: "---",
        },
        {
          index: 3,
          name: "非法占用",
          code: 0,
          operate: "---",
        },
      ],
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询部门列表 */
    getList() {
      this.loading = true;

      this.deptList = moni.data.list;
      this.total = moni.data.total;
      this.loading = false;
    },
    /** 转换部门数据结构 */
    normalizer(node) {
      if (node.children && !node.children.length) {
        delete node.children;
      }
      return {
        id: node.deptId,
        label: node.deptName,
        children: node.children,
      };
    },

    /** 搜索按钮操作 */
    handleQuery() {
      this.getList();
    },

    /** 修改按钮操作 */
    handleUpdate(row) {
      this.$refs.attr_dia.open = true;
    },
  },
};
</script>
<style lang="scss" scoped>
.el-table {
  

}

.app-container{
  display: flex;
  flex-direction: column;
}
</style>
<style lang="scss">
.el-table__expanded-cell{
padding: 0;
}

.innner{
  td{
    padding: 0 !important;
  }

}</style>